export const getWeek = (date) => {
	let nowYear = new Date().getFullYear()
	let newDate = `${nowYear}/${date}`
	var dateObj = new Date(newDate); //定义日期对象
	var day = dateObj.getDay(); //获取星期几
	let week = ''
	switch (day) {
	    case 0:
	        week = '周日'
	        break;
	    case 1:
	        week = '周一'
	        break;
	    case 2:
	        week = '周二'
	        break;
	    case 3:
	        week = '周三'
	        break;
	    case 4:
	        week = '周四'
	        break;
	    case 5:
	        week = '周五'
	        break;
	    case 6:
	        week = '周六'
	        break;
	}
	return week;
}

//获取年月
export const getYM = (day) => {
	let myDate = new Date()
	let myYear = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
	let myMonth = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
	let myToday = myDate.getDate(); //获取当前日(1-31)
	myMonth = myMonth > 9 ? myMonth : '0' + myMonth
	myToday = myToday > 9 ? myToday : '0' + myToday
	let nowDate = ''
	if (day) {
		day = +day > 9 ? day : '0' + day
		nowDate = myYear + '-' + myMonth + '-' + day
	} else {
		nowDate = myYear + '-' + myMonth
	}
	return nowDate
}

// 获取包含当天之后30天的日期
export const initDate = () => {
    let dateList = [];
    let startDate = new Date();
    let endDate = new Date();
	let nowYear = new Date().getFullYear()

    // setDate:根据本地时间来指定一个日期对象的天数
    // getDate:返回一个指定的日期对象为一个月中的哪一日
    endDate.setDate(startDate.getDate() + 30);
    // startDate.setDate(startDate.getDate() + 1);
    while (endDate.getTime() - startDate.getTime() >= 0) {
        // getMonth返回一个 0 到 11 的整数值：0 代表一月份，1 代表二月份，2 代表三月份，依次类推。
        let month = (startDate.getMonth() + 1).toString().length === 1 ? "0" + (startDate.getMonth() + 1).toString() : startDate.getMonth() + 1
        // getDate() 返回一个 1 到 31 的整数值。
        let day = startDate.getDate().toString().length === 1 ? "0" + startDate.getDate() : startDate.getDate()
        dateList.push({
			date: month + "/" + day,
			specificDate: `${nowYear}-${month}-${day} 00:00:00`
		})
        startDate.setDate(startDate.getDate() + 1)
    }
    return dateList;
}


export const nonceStr = () => {
	const str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	let Str = ''
	for (let i = 0; i < 32; i++) {
		const radomNum = Math.floor(Math.random() * (str.length + 1)) //含最大值，含最小值
		Str = Str + str[radomNum]
	}
	return Str
}